/* 寻找匹配第一个 */
function findFirst() {
    let myText = "catuuuu===cut";
    let retObj = myText.match(new RegExp("c[auo]t"));
    console.log(retObj);   // [ 'cat', index: 0, input: 'catuuuu===cut' ]
}

/* 寻找匹配全部(最实用) */
function findAll() {
    let myText = "catuuuu===cut";
    let textList = myText.match(new RegExp("c[auo]t", "g"));
    console.log(textList);   // [ 'cat', 'cut' ]
}

/* 代替第一个成功匹配的 */
function replaceFirst() {
    let myText = "catuuuu===cut";
    let newText = myText.replace(new RegExp("c[auo]t"), "X");
    console.log(newText);
}

/* 代替所有匹配的 */
function replaceAll() {
    let myText = "catuuuu===cut";
    let newText = myText.replace(new RegExp("c[auo]t", "g"), "X");
    console.log(newText);
}

/* 匹配 */
function match() {
    let reg = new RegExp("^abc", "i");
    let isMatch = reg.test("Abcdefg");
    console.log(isMatch);
}

/* es5的正则对象 */
function matchEs5() {
    let reg = /^abc/i;
    let isMatch = reg.test("Abcdefg");
    console.log(isMatch);
}

/* 寻找第一个匹配的字符串, 找不到则返回null */
function findFirst1() {
    let reg = new RegExp("c[auo]t");
    let retObj = reg.exec("catuuuu===cut");
    console.log(retObj);
}




findFirst()